<template>
	<view>
		<view class="item card-bg" v-for="(item) in list_data" :key="item">
			<view class="top-wrap">
				<text class="title">{{item.name}}</text>
				<view class="spe"></view>
				<!-- <text class="people">{{item.capacity || 0}}人</text> -->
			</view>
			<view class="ask-wrap">
				<text class="label">会议列表</text>
				<view class="spe">
				</view>
				<button type="primary" class="btn-ask" @click="toReserve(item)">预约</button>
			</view>
			<view class="empty-ask" v-if="false">
				暂无预约
			</view>
			<view class="ask-item-wrap" v-for="(itm,idx) in item.meetingList" :key="itm" @click="toReserveDetailView(itm)">
				<text class="time">{{formatTime(itm)}}</text>
				<text class="title">{{itm.title}} </text>
			</view>
		</view>
		<uni-load-more status="loading" v-show="isLoading" />
		<xw-empty v-if="!list_data.length" v-on:refresh="onRefressh"></xw-empty>
	</view>
</template>

<script>
	import cfg from '@/utils/config.js'
	import time_util from '@/utils/time_util.js'
	export default {
		data() {
			return {
				page: 1,
				isLoading: false,
				list_data: []
			}
		},
		onPullDownRefresh() {
			this.onRefressh()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 2000)
		},
		onReachBottom() {
			this.page++;
			this.isLoading = true
			this.getList()
		},
		onLoad() {
			uni.hideHomeButton()
		},
		onShow() {
			this.onRefressh()
		},

		methods: {
			onRefressh() {
				this.page = 1
				this.getList()
			},
			getList() {
				uni.request({
					url: cfg.host + 'meeting/query-meeting-and-room',
					method: 'POST',
					data: {
						'pageNo': this.page
					},
					success: (res) => {
						if (res.data.code == 0) {
							let list = res.data.data.list || []
							if (this.page == 1) {
								this.list_data = list
							} else {
								this.list_data = this.list_data.concat(list)
							}
						}
					},
					complete: () => {
						this.isLoading = false
					}
				})
			},
			formatTime(itm) {
				let begin = itm.beginTime
				let end = itm.endTime

				let md = time_util.getMD(begin)
				let time = time_util.getHM(begin) + "-" + time_util.getHM(end)

				return md + "\n" + time
			},
			toReserve(item) {
				uni.navigateTo({
					url: '/pages1/metting/reserve/add?roomId=' + item.id + '&roomName=' + item.name
				})
			},
			toReserveDetailView(item) {
				uni.navigateTo({
					url: '/pages1/metting/reserve/detail_view?id='+item.id
				})
			}
		}
	}
</script>

<style lang="scss">
	.item {
		display: flex;
		flex-direction: column;

		.top-wrap {
			display: flex;
			flex-direction: row;
			align-items: center;
			box-sizing: border-box;
			padding-top: 10rpx;
			padding-bottom: 24rpx;
			border-bottom: 1rpx solid #f4f4f4;

			.dot-red {
				width: 16rpx;
				height: 16rpx;
				background-color: red;
				border-radius: 16rpx;
			}

			.dot-green {
				width: 16rpx;
				height: 16rpx;
				background-color: green;
				border-radius: 16rpx;
			}

			.title {
				font-size: 32rpx;
				color: black;
				margin-left: 10rpx;
			}

			.people {
				font-size: 26rpx;
			}

			.ic-set {
				width: 40rpx;
				height: 40rpx;
				box-sizing: border-box;
				padding: 2rpx;
				margin-left: 32rpx;
			}
		}

		.ask-wrap {
			display: flex;
			flex-direction: row;
			margin-top: 24rpx;
			align-items: center;
			margin-bottom: 20rpx;

			.label {
				font-size: 28rpx;
			}

			.arr {
				width: 26rpx;
				height: 26rpx;
				margin-left: 5rpx;
			}

			.btn-ask {
				width: 120rpx;
				height: 50rpx;
				font-size: 26rpx;
				line-height: 50rpx;
			}
		}

		.empty-ask {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 28rpx;
			color: #666;
			height: 100rpx;
		}

		.ask-item-wrap {
			display: flex;
			flex-direction: row;
			box-sizing: border-box;
			padding-bottom: 30rpx;
			padding-top: 30rpx;
			border-bottom: 1rpx solid #f4f4f4;

			.time {
				font-size: 24rpx;
				color: #222;
			}

			.title {
				flex: 1;
				font-size: 28rpx;
				margin-left: 40rpx;
				color: #222;
			}
		}
	}
</style>